package com.wang.designpattern.singleton.type6;

public class SingletonTest06 {

    public static void main(String[] args) {
        System.out.println("枚举");
        Singleton singleton1 = Singleton.INSTANCE;
        Singleton singleton2 = Singleton.INSTANCE;
        System.out.println(singleton1 == singleton2);
        System.out.println("singleton1.hashCode() == " + singleton1.hashCode());
        System.out.println("singleton2.hashCode() == " + singleton2.hashCode());
        singleton1.hello();
    }

}

// 使用枚举enum实现单例
enum Singleton {
    INSTANCE;
    public void hello() {
        System.out.println("hello world!");
    }
}
